/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import entidades.Cargos;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author Renato
 */

public class CargosConverter implements Converter {

    public Object getAsObject(FacesContext facesContext, UIComponent component, String string) {

        if (string == null || string.length() == 0) {
            return null;
        }
        Integer id = new Integer(string);
        CargosJpaController cargos = new CargosJpaController();
        // CargosJpaController controller = (CargosJpaController) facesContext.getApplication().getVariableResolver().resolveVariable(facesContext, "CargosJpaController");
        return cargos.findCargos(id);
    }

    public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
    
        if (object == null) {
            return null;
        }
            String id = object.toString();
            return id;
    }

}
